//
//  MainTabBarController.m
//  BaseProject
//
//  Created by lianjie on 2017/10/31.
//  Copyright © 2017年 lianjie. All rights reserved.
//

#import "MainTabBarController.h"
#import "MainNavController.h"

//#import "HomeViewController.h"
@interface MainTabBarController ()<UITabBarControllerDelegate>

@end

@implementation MainTabBarController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    self.delegate = self;
    BaseViewController *homePage = [[NSClassFromString(@"GroupHomeViewController") alloc]init];
    
    BaseViewController *secondPage = [[NSClassFromString(@"MessageHomeViewController") alloc]init];
    BaseViewController *thirdPage = [[NSClassFromString(@"OtherViewController") alloc]init];
    
    
    ///首页
    
    [self addchildVc:homePage title:@"群活动" image:@"shouye2" selectImage:@"shouye2"];
    MainNavController *homeNav = [[MainNavController alloc]initWithRootViewController:homePage];
//
    ///消息
    [self addchildVc:secondPage title:@"消息" image:@"dangjianfuwu2" selectImage:@"dangjianfuwu2"];
    MainNavController *messageNav = [[MainNavController alloc]initWithRootViewController:secondPage];
    
//    ///其他
    [self addchildVc:thirdPage title:@"其他" image:@"dangqunhudong2" selectImage:@"dangqunhudong2"];
    MainNavController *JMNav = [[MainNavController alloc]initWithRootViewController:thirdPage];
    
    self.viewControllers = @[homeNav,messageNav,JMNav];
    
}













/**
 
 添加一个子控制器
 
 1、childVc。    子控制器
 2、title。       标题
 3、image         图片
 4、selectImage。  选中的图片
 
 */
-(void) addchildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectImage:(NSString *)selectImage
{
    
    
//    [self setValue:[[CustomTabbar alloc]init] forKey:@"tabBar"];
    ///设置tabbar不透明
    
    [[UITabBar appearance] setTranslucent:NO];
    
    ///设置tabbar的颜色
    
    [[UITabBar appearance] setTintColor:WhiteColor];
    
    
    ///设置子控制器上的文字
    
    childVc.title = title;
    
    
    ///设置子控制器的图片
    //状态1
    childVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //状态2
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    ///imageWithRenderingMode 防止被tint color渲染成蓝色
    
    CGFloat textFont = 14;
    
    ///设置文字样式
    //状态1
    [childVc.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:textFont],NSForegroundColorAttributeName:BlackColor} forState:UIControlStateNormal];
    //状态2
    [childVc.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:textFont],NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
    
    
    
    
    
    
}


//-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
//{
//
//
//
//}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
